<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>在Ubuntu上从0开始配置深度学习开发环境 | 啊粥啊周舟の部落阁</title><meta name="author" content="Zhouwy"><meta name="copyright" content="Zhouwy"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="在Ubuntu上从0开始配置深度学习开发环境1、安装ubuntu server1.1 Ventoy 启动U盘简单来说，Ventoy是一个制作可启动U盘的开源工具。有了Ventoy你就无需反复地格式化U盘，你只需要把 ISO&#x2F;WIM&#x2F;IMG&#x2F;VHD(x)&#x2F;EFI 等类型的文件直接拷贝到U盘里面就可以启动了，无需其他操作。你可以一次性拷贝很多个不同类型的镜像文件，Ventoy 会在启动时显示一个菜单来">
<meta property="og:type" content="article">
<meta property="og:title" content="在Ubuntu上从0开始配置深度学习开发环境">
<meta property="og:url" content="https://gitee.com/zwyywz/zwyywz.git/2023/04/15/%E5%9C%A8ubuntu%E4%B8%8A%E4%BB%8E0%E5%BC%80%E5%A7%8B%E9%85%8D%E7%BD%AE%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/index.html">
<meta property="og:site_name" content="啊粥啊周舟の部落阁">
<meta property="og:description" content="在Ubuntu上从0开始配置深度学习开发环境1、安装ubuntu server1.1 Ventoy 启动U盘简单来说，Ventoy是一个制作可启动U盘的开源工具。有了Ventoy你就无需反复地格式化U盘，你只需要把 ISO&#x2F;WIM&#x2F;IMG&#x2F;VHD(x)&#x2F;EFI 等类型的文件直接拷贝到U盘里面就可以启动了，无需其他操作。你可以一次性拷贝很多个不同类型的镜像文件，Ventoy 会在启动时显示一个菜单来">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.educba.com/academy/wp-content/uploads/2020/01/Deep-Learning.jpg">
<meta property="article:published_time" content="2023-04-15T01:25:00.000Z">
<meta property="article:modified_time" content="2023-04-15T12:21:01.584Z">
<meta property="article:author" content="Zhouwy">
<meta property="article:tag" content="DeepLearning">
<meta property="article:tag" content="开发环境">
<meta property="article:tag" content="系统安装">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.educba.com/academy/wp-content/uploads/2020/01/Deep-Learning.jpg"><link rel="shortcut icon" href="/zwyywz/img/favicon.png"><link rel="canonical" href="https://gitee.com/zwyywz/zwyywz.git/2023/04/15/%E5%9C%A8ubuntu%E4%B8%8A%E4%BB%8E0%E5%BC%80%E5%A7%8B%E9%85%8D%E7%BD%AE%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/zwyywz/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/zwyywz/',
  algolia: undefined,
  localSearch: undefined,
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":300},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: Zhouwy","link":"链接: ","source":"来源: 啊粥啊周舟の部落阁","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '在Ubuntu上从0开始配置深度学习开发环境',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-04-15 20:21:01'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="///at.alicdn.com/t/c/font_4018630_wl3l75i04vl.css"><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/zwyywz/img/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/zwyywz/archives/"><div class="headline">文章</div><div class="length-num">17</div></a><a href="/zwyywz/tags/"><div class="headline">标签</div><div class="length-num">29</div></a><a href="/zwyywz/categories/"><div class="headline">分类</div><div class="length-num">5</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/zwyywz/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 分类</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/zwyywz/note/"><i class="fa-fw iconfont icon-xuexibiji"></i><span> 学习笔记</span></a></li><li><a class="site-page child" href="/zwyywz/opensource/"><i class="fa-fw iconfont icon-xiangmu"></i><span> 开源项目</span></a></li><li><a class="site-page child" href="/zwyywz/development/"><i class="fa-fw iconfont icon-peizhi-xitongpeizhi"></i><span> 环境配置</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/zwyywz/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/zwyywz/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/zwyywz/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://cdn.educba.com/academy/wp-content/uploads/2020/01/Deep-Learning.jpg')"><nav id="nav"><span id="blog-info"><a href="/zwyywz/" title="啊粥啊周舟の部落阁"><span class="site-name">啊粥啊周舟の部落阁</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/zwyywz/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 分类</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/zwyywz/note/"><i class="fa-fw iconfont icon-xuexibiji"></i><span> 学习笔记</span></a></li><li><a class="site-page child" href="/zwyywz/opensource/"><i class="fa-fw iconfont icon-xiangmu"></i><span> 开源项目</span></a></li><li><a class="site-page child" href="/zwyywz/development/"><i class="fa-fw iconfont icon-peizhi-xitongpeizhi"></i><span> 环境配置</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/zwyywz/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/zwyywz/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/zwyywz/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">在Ubuntu上从0开始配置深度学习开发环境</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-04-15T01:25:00.000Z" title="发表于 2023-04-15 09:25:00">2023-04-15</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-15T12:21:01.584Z" title="更新于 2023-04-15 20:21:01">2023-04-15</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/zwyywz/categories/%E5%BC%80%E5%8F%91%E6%95%99%E7%A8%8B/">开发教程</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/zwyywz/categories/%E5%BC%80%E5%8F%91%E6%95%99%E7%A8%8B/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">学习笔记</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="在Ubuntu上从0开始配置深度学习开发环境"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="在Ubuntu上从0开始配置深度学习开发环境"><a href="#在Ubuntu上从0开始配置深度学习开发环境" class="headerlink" title="在Ubuntu上从0开始配置深度学习开发环境"></a>在Ubuntu上从0开始配置深度学习开发环境</h1><h2 id="1、安装ubuntu-server"><a href="#1、安装ubuntu-server" class="headerlink" title="1、安装ubuntu server"></a>1、安装ubuntu server</h2><h3 id="1-1-Ventoy-启动U盘"><a href="#1-1-Ventoy-启动U盘" class="headerlink" title="1.1 Ventoy 启动U盘"></a>1.1 Ventoy 启动U盘</h3><p>简单来说，Ventoy是一个制作可启动U盘的开源工具。有了Ventoy你就无需反复地格式化U盘，你只需要把 ISO/WIM/IMG/VHD(x)/EFI 等类型的文件直接拷贝到U盘里面就可以启动了，无需其他操作。你可以一次性拷贝很多个不同类型的镜像文件，Ventoy 会在启动时显示一个菜单来供你进行选择。详细使用请看官网：<a target="_blank" rel="noopener" href="https://www.ventoy.net/cn/index.html">ventoy官网</a></p>
<p> 下载好后解压，解压完成后，双击运行“<strong>ventoy2disk.exe</strong>”打开它。</p>
<p><img src="https://img2022.cnblogs.com/blog/1423839/202207/1423839-20220719160727690-1416001875.png" alt="img"></p>
<p>Ventoy 安装完成之后，U盘会被分成两个区。第一个分区将会被默认格式化为 exFAT 格式的文件系统，你可以在这里存放日常使用的普通文档，当普通 U 盘使用。当你需要制作启动盘时，你只需要把系统镜像文件 .iso 拷贝到这个分区里面即可。</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/fenqu.png!0x0.webp" alt=""></p>
<p>关机重启，选择从U盘启动，不同主板的启动方式不一样，请自行百度。启动后就可以看到如下页面。</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/2251681530170_.pic.jpg" alt=""></p>
<h3 id="1-2-安装ubuntu-server"><a href="#1-2-安装ubuntu-server" class="headerlink" title="1.2 安装ubuntu server"></a>1.2 安装ubuntu server</h3><p>当开启安装Ubuntu按钮后，会短暂出现如下只显示logo的图形界面，此时可以默认不操作，则会直接 进入下面步骤2的语言选择界面。</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415150548933.png" alt=""></p>
<p>选择键盘 本步骤直接默认按回车即可。</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415150615237.png" alt=""></p>
<p>3.选择Install <a target="_blank" rel="noopener" href="https://so.csdn.net/so/search?q=Ubuntu&amp;spm=1001.2101.3001.7020">Ubuntu</a> 安装乌班图，回车 </p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415150634632.png" alt="img"></p>
<p>  根据你的网络情况，如果是网线插好，有DHCP，系统就会自动默认为DHCP，并把已经获取到的IP显示到对应的网卡上。使用DHCP就直接光标选择Done，回车。</p>
<p>  如果需要调整为静态，可以移动光标到对应网卡处，回车，出现下级菜单。选择 Edit IPv4/Edit IPv6， 回车 ，对IPv4和IPv6进行编辑</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415150717168.png" alt=""></p>
<p>设置IPv4静态IP</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415150844532.png" alt=""></p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415150851431.png" alt=""></p>
<p>设置代理服务器，一般不需要，默认为空，选择Done,回车。 </p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415150902977.png" alt=""></p>
<p>设置安装软件、更新源，选择Done,回车。 默认为ubuntu的国外服务器， 此处已经修改为阿里云的更新源（<a target="_blank" rel="noopener" href="http://mirrors.aliyun.com/ubuntu），相对来说，速度会更稳定，喜欢其他更新源的同志，可以自行更改为对应源地址，例如网易，中科大。">http://mirrors.aliyun.com/ubuntu），相对来说，速度会更稳定，喜欢其他更新源的同志，可以自行更改为对应源地址，例如网易，中科大。</a></p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415150929819.png" alt=""></p>
<p>磁盘分区 。  如果对手动分区不熟悉的同志，可以直接选择Use An Entire Disk 回车.这个就是整个盘分为一个区（<strong>会抹掉整个盘哟，做好数据备份</strong>）。新手同志可以先选这个，可以快速安装环境，进入学习。 选择Manual进入手动分区。</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415151004127.png" alt=""></p>
<p> 光标移动到未分区的磁盘处，回车，进入下级菜单，选择Add Partition 回车，添加分区。</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415151102556.png" alt=""></p>
<p>在Size处添入XXG（XX为数值）。要记得输入G，不然系统会未识别。</p>
<p> 在Format处选择分区格式，一般常见的为ext4,xfs，需要内存交互区的选择swap </p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415151154097.png" alt=""></p>
<p><strong>分区建议 /boot 2-5G 可自行选择，swap分区建议1-2倍物理内存大小，/ 根目录为剩余空间40%，/home目录为剩余空间60%</strong></p>
<p>无论是自动分区，还是手动分区，最后分区前都会把当前分区情况显示出来，如果没问题就选择Done,回车。 </p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415151444640.png" alt=""></p>
<p>一般格式化前都会一个警告提醒你该操作是不可逆的，我们移动光标选择Continue 回车继续。</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415151455473.png" alt=""></p>
<p>设置用户名，密码。ROOT用户是默认存在，这里是不能使用ROOT为用户名。而且这里的密码没有强制要求高强度验证，真的是让人神奇 。Centos7安装时设置密码是必须要足够复杂才能通过验证</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415151510296.png" alt=""></p>
<p>是否安装SSH。如果有需要远程登陆的同志可以选择安装。下面Import SSH identity 默认选 NO就可以，选择Done 回车 。建议选择yes。我们一般靠远程开发。</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415151525550.png" alt=""></p>
<p>系统服务安装清单，一般都是直接选择Done 回车，进入安装模式。 </p>
<p><img src="https://img-blog.csdnimg.cn/20190621171350252.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70" alt=""></p>
<p>安装模式</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415151618571.png" alt=""></p>
<p>安装完成，选择Reboot now。重启电脑 </p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Rqc3hpbg==,size_16,color_FFFFFF,t_70-20230415151632001.png" alt=""></p>
<h3 id="1-3-远程连接"><a href="#1-3-远程连接" class="headerlink" title="1.3 远程连接"></a>1.3 远程连接</h3><p>查看<code>ssh</code>服务是否启动：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">systemctl status ssh</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">打开一下防火墙</span></span><br><span class="line">sudo ufw ssh</span><br></pre></td></tr></table></figure>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415151855774.png" alt="image-20230415151855774"></p>
<p>如果不是正常启动，可以输入<code>systemctl start ssh</code></p>
<p>在自己的电脑上就可以打开终端工具，远程连接了。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh usrname@ip -p 22</span><br></pre></td></tr></table></figure>
<p>配置一下<code>vscode</code>远程连接，就可以开心的远程coding了。</p>
<p>首先安装一下<code>remote-ssh</code>插件，安装完成后，左下角就会出现远程连接图标。</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415152549124.png" alt=""></p>
<p>点击图标，就会出现弹窗</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415152654518.png" alt=""></p>
<p>选择第一项，输入<code>ssh usrname@ip -p 22</code></p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415152816273.png" alt=""></p>
<p>输入密码即可！</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415152850894.png" alt=""></p>
<h2 id="2、配置基础开发环境"><a href="#2、配置基础开发环境" class="headerlink" title="2、配置基础开发环境"></a>2、配置基础开发环境</h2><h3 id="2-1-更换国内源以及配置科学上网"><a href="#2-1-更换国内源以及配置科学上网" class="headerlink" title="2.1 更换国内源以及配置科学上网"></a>2.1 更换国内源以及配置科学上网</h3><p>Ubuntu配置的默认源并不是国内的服务器，下载更新软件都比较慢。首先备份源列表文件<code>sources.list</code>：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup</span><br></pre></td></tr></table></figure>
<p>打开sources.list文件修改，选择合适的源，替换原文件的内容，保存编辑好的文件, 以阿里云更新服务器为例（可以分别测试阿里云、清华、中科大、163源的速度，选择最快的）：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo vim /etc/apt/sources.list</span><br></pre></td></tr></table></figure>
<p>编辑<code>/etc/apt/sources.list</code>文件, 在文件最前面添加阿里云镜像源：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash"> 阿里源</span></span><br><span class="line">deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse</span><br><span class="line">deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse</span><br><span class="line">deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse</span><br><span class="line">deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse</span><br><span class="line">deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse</span><br><span class="line">deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse</span><br><span class="line">deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse</span><br><span class="line">deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse</span><br><span class="line">deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse</span><br><span class="line">deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse</span><br></pre></td></tr></table></figure>
<p>更新：速度杠杠的!</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get update</span><br><span class="line">sudo apt-get upgrade</span><br><span class="line">sudo apt-get install build-essential</span><br><span class="line">sudo apt-get install curl git</span><br></pre></td></tr></table></figure>
<p>配置<code>proxychains</code>用以科学上网</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo apt install proxychains #安装proxychains</span><br><span class="line">sudo vi /etc/proxychains.conf</span><br></pre></td></tr></table></figure>
<p>在最下面添加配置，增加http和https协议代理：</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415120211346.png" alt=""></p>
<p>试试代理效果</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415120343698.png" alt=""></p>
<h3 id="2-2-安装zsh和oh-my-zsh-，提升终端效率"><a href="#2-2-安装zsh和oh-my-zsh-，提升终端效率" class="headerlink" title="2.2 安装zsh和oh-my-zsh ，提升终端效率"></a>2.2 安装zsh和oh-my-zsh ，提升终端效率</h3><ul>
<li>安装zsh</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo apt install zsh #安装zsh</span><br><span class="line">sudo chsh -s /bin/zsh #将zsh设置成默认shell（不设置的话启动zsh只有直接zsh命令即可）</span><br></pre></td></tr></table></figure>
<ul>
<li>安装oh-my-zsh</li>
</ul>
<p>找了一个国内的镜像源下载了oh-my-zsh的install.sh</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sh -c &quot;$(curl -fsSL https://gitee.com/shmhlsy/oh-my-zsh-install.sh/raw/master/install.sh)&quot; #国内镜像源</span><br></pre></td></tr></table></figure>
<ul>
<li>安装插件</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">zsh-autosuggestions 命令行命令键入时的历史命令建议</span></span><br><span class="line">git clone https://github.com/zsh-users/zsh-autosuggestions $&#123;ZSH_CUSTOM:-~/.oh-my-zsh/custom&#125;/plugins/zsh-autosuggestions</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">zsh-syntax-highlighting 命令行语法高亮插件</span></span><br><span class="line">git clone https://gitee.com/Annihilater/zsh-syntax-highlighting.git $&#123;ZSH_CUSTOM:-~/.oh-my-zsh/custom&#125;/plugins/zsh-syntax-highlighting</span><br></pre></td></tr></table></figure>
<ul>
<li>配置文件~/.zshrc:</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">vim ~/.zshrc</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">添加一下内容</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">防止中文乱码</span></span><br><span class="line">export LC_ALL=en_US.UTF-8</span><br><span class="line">export LANG=en_US.UTF-8</span><br><span class="line">ZSH_THEME=&quot;ys&quot;</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">配置要使用的插件</span></span><br><span class="line">plugins=(</span><br><span class="line">        git</span><br><span class="line">        extract</span><br><span class="line">        zsh-autosuggestions</span><br><span class="line">        zsh-syntax-highlighting</span><br><span class="line">)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415121616649.png" alt=""></p>
<h2 id="3、安装显卡驱动以及CUDA"><a href="#3、安装显卡驱动以及CUDA" class="headerlink" title="3、安装显卡驱动以及CUDA"></a>3、安装显卡驱动以及CUDA</h2><h3 id="3-1-安装显卡驱动"><a href="#3-1-安装显卡驱动" class="headerlink" title="3.1. 安装显卡驱动"></a>3.1. 安装显卡驱动</h3><p>在终端输入：<code>sudo ubuntu-drivers devices</code>，可以看到如下界面：</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415121810255.png" alt=""></p>
<p>从上图可以看出，我的显卡是：<code>GP104GL [Quadro P4000]</code>，推荐安装的版本号是：<code>nnvidia-driver-470 - distro non-free recommended</code>。</p>
<p>如果同意安装推荐版本，那我们只需要终端输入：<code>sudo ubuntu-drivers autoinstall</code> 就可以自动安装了。</p>
<p>当然我们也可以使用 apt 命令安装自己想要安装的版本，比如我想安装 <code>340</code> 这个版本号的版本，终端输入：<code>sudo apt install nvidia-driver-418-server</code> 就自动安装了。</p>
<p>安装完成后<strong>重启</strong>，可使用<code>nvidia-smi</code>查看</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415122953696.png" alt=""></p>
<h3 id="3-2-安装CUDA"><a href="#3-2-安装CUDA" class="headerlink" title="3.2 安装CUDA"></a>3.2 安装CUDA</h3><p>以下脚本仅适用于x64_x86的 ubuntu18.04 系统，其他系统请看<a target="_blank" rel="noopener" href="https://developer.nvidia.com/cuda-downloads">Nvidia官网</a>。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin</span><br><span class="line"></span><br><span class="line">sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600</span><br><span class="line"></span><br><span class="line">wget https://developer.download.nvidia.com/compute/cuda/11.1.0/local_installers/cuda-repo-ubuntu1804-11-1-local_11.1.0-455.23.05-1_amd64.deb</span><br><span class="line"></span><br><span class="line">sudo dpkg -i cuda-repo-ubuntu1804-11-1-local_11.1.0-455.23.05-1_amd64.deb</span><br><span class="line">sudo apt-key add /var/cuda-repo-ubuntu1804-11-1-local/7fa2af80.pub</span><br><span class="line"></span><br><span class="line">sudo apt-get update</span><br><span class="line">sudo apt-get -y install cuda</span><br></pre></td></tr></table></figure>
<p>安装完成后，将CUDA添加进环境变量<code>vim ~/.zshrc</code></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">export CUDA_ROOT=/usr/local/cuda</span><br><span class="line">export PATH=$PATH:$CUDA_ROOT/bin</span><br></pre></td></tr></table></figure>
<p>之后<code>source ~/.zshrc</code>，在命令行输入<code>nvcc -V</code></p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415130434831.png" alt=""></p>
<h2 id="4、配置深度学习开发环境"><a href="#4、配置深度学习开发环境" class="headerlink" title="4、配置深度学习开发环境"></a>4、配置深度学习开发环境</h2><h3 id="4-1-安装conda用以管理python版本"><a href="#4-1-安装conda用以管理python版本" class="headerlink" title="4.1 安装conda用以管理python版本"></a>4.1 安装conda用以管理python版本</h3><ul>
<li>下载 conda,我这使用的是Miniconda3，如果需要Anaconda3 请自行下载，安装方法一样。</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_23.1.0-1-Linux-x86_64.sh</span><br><span class="line">bash Miniconda3-py310_23.1.0-1-Linux-x86_64.sh # 执行脚本</span><br></pre></td></tr></table></figure>
<ul>
<li>检查是否将conda添加进环境变量，如果没有就将以下内容添加进<code>~/.zshrc</code>,一般来说是会自动添加的。</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">added by Miniconda3 4.5.12 installer</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">&gt;&gt;&gt; conda init &gt;&gt;&gt;</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">!! Contents within this block are managed by <span class="string">&#x27;conda init&#x27;</span> !!</span></span><br><span class="line">__conda_setup=&quot;$(CONDA_REPORT_ERRORS=false &#x27;/home/zwy/miniconda3/bin/conda&#x27; shell.bash hook 2&gt; /dev/null)&quot;</span><br><span class="line"> if [ $? -eq 0 ]; then</span><br><span class="line">    \eval &quot;$__conda_setup&quot;</span><br><span class="line"> else</span><br><span class="line">    if [ -f &quot;/home/zwy/miniconda3/etc/profile.d/conda.sh&quot; ]; then</span><br><span class="line">         . &quot;/home/zwy/miniconda3/etc/profile.d/conda.sh&quot;</span><br><span class="line">         CONDA_CHANGEPS1=false conda activate base</span><br><span class="line">     else</span><br><span class="line">        \export PATH=&quot;/home/zwy/miniconda3/bin:$PATH&quot;</span><br><span class="line">   fi</span><br><span class="line">fi</span><br><span class="line">unset __conda_setup</span><br></pre></td></tr></table></figure>
<p>  <code>conda info</code>查看conda基本信息：</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415131832748.png" alt=""></p>
<p>Conda默认的软件源在国外,速度非常的慢,我们可以将其更换为清华源,如果你是用的是教育网,那么软件下载速度会非常快。</p>
<p>先执行<code>conda config --set show_channel_urls yes</code>，修改用户目录下的 <code>.condarc</code> 文件来使用 TUNA 镜像源。<br><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">vi ~/.condarc</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">写入以下内容</span></span><br><span class="line">channels:</span><br><span class="line">  - defaults</span><br><span class="line">show_channel_urls: true</span><br><span class="line">default_channels:</span><br><span class="line">  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main</span><br><span class="line">  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r</span><br><span class="line">  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2</span><br><span class="line">custom_channels:</span><br><span class="line">  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud</span><br><span class="line">  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud</span><br><span class="line">  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud</span><br><span class="line">  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud</span><br><span class="line">  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud</span><br><span class="line">  pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud</span><br><span class="line">  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud</span><br></pre></td></tr></table></figure></p>
<h3 id="4-2-PyTorch-开发环境"><a href="#4-2-PyTorch-开发环境" class="headerlink" title="4.2 PyTorch 开发环境"></a>4.2 PyTorch 开发环境</h3><ul>
<li>```shell<br>conda create —name torch python==3.8.0 #新建虚拟环境<br>conda activate torch # 激活虚拟环境<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">给pip换个源：</span><br><span class="line"></span><br><span class="line">```shell</span><br><span class="line"># 使用本镜像站来升级 pip</span><br><span class="line">pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple pip -U</span><br><span class="line">pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>  安装<a target="_blank" rel="noopener" href="https://pytorch.org/get-started/locally/">Pytoch</a>，可以自由选择版本，我这选择v1.8.2 with LTS support</p>
  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">CUDA 11.1</span></span><br><span class="line">pip3 install torch==1.8.2 torchvision==0.9.2 torchaudio==0.8.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cu111</span><br></pre></td></tr></table></figure>
<p>  <img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415134009562.png" alt=""></p>
<p>测试一下：</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415134625189.png" alt=""></p>
<h3 id="4-2-TensorFlow-开发环境"><a href="#4-2-TensorFlow-开发环境" class="headerlink" title="4.2 TensorFlow 开发环境"></a>4.2 TensorFlow 开发环境</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">conda create --name tf2X python==3.8.0 #新建虚拟环境</span><br><span class="line">conda activate tf2X # 激活虚拟环境</span><br><span class="line">conda search tensorflow-gpu # 看看有什么版本可用</span><br></pre></td></tr></table></figure>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415134932406.png" alt=""></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">安装tensorflow-gpu=2.4.1</span></span><br><span class="line">conda install tensorflow-gpu=2.4.1</span><br></pre></td></tr></table></figure>
<p>测试一下：应该可以用</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415135414647.png" alt=""></p>
<h2 id="5、TRT模型部署"><a href="#5、TRT模型部署" class="headerlink" title="5、TRT模型部署"></a>5、TRT模型部署</h2><h3 id="5-1-安装TensorRT"><a href="#5-1-安装TensorRT" class="headerlink" title="5.1 安装TensorRT"></a>5.1 安装TensorRT</h3><p>NVIDIA TensorRT 是一个用于深度学习推理的 SDK 。 TensorRT 提供了 API 和解析器，可以从所有主要的深度学习框架中导入经过训练的模型。然后，它生成可在数据中心以及汽车和嵌入式环境中部署的优化运行时引擎。</p>
<p>为了方便学习，我们就下载源码版本，而不下载安装版本：我这里选择的是：NVIDIA TensorRT 8.2 GA版本。如需其他版本，可<a target="_blank" rel="noopener" href="https://developer.nvidia.com/nvidia-tensorrt-download">自行下载</a></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">下载源码</span></span><br><span class="line">wget https://developer.nvidia.com/compute/machine-learning/tensorrt/secure/8.2.1/tars/tensorrt-8.2.1.8.linux.x86_64-gnu.cuda-11.4.cudnn8.2.tar.gz</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">解压</span></span><br><span class="line">tar -xvzf tensorrt-8.2.1.8.linux.x86_64-gnu.cuda-11.4.cudnn8.2.tar.gz</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">我不喜欢名字太长，所以重命名一下</span></span><br><span class="line">mv tensorrt-8.2.1.8.linux.x86_64-gnu.cuda-11.4.cudnn8.2 Tensorrt-8.2.1</span><br></pre></td></tr></table></figure>
<p>将TensorRT添加到链接库，<code>vim ~/.zshrc</code></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">export TRT_ROOT=/your tensorrt path/</span><br><span class="line">export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TRT_ROOT/lib</span><br></pre></td></tr></table></figure>
<p>为了避免其它软件找不到 TensorRT 的库，建议把 TensorRT 的库和头文件添加到系统路径下</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">TensorRT路径下</span></span><br><span class="line">sudo cp -r ./lib/* /usr/lib</span><br><span class="line">sudo cp -r ./include/* /usr/include</span><br></pre></td></tr></table></figure>
<h3 id="5-2-安装cuDNN"><a href="#5-2-安装cuDNN" class="headerlink" title="5.2 安装cuDNN"></a>5.2 安装cuDNN</h3><p>NVIDIA CUDA® 深度神经网络库(cuDNN) <strong>是一个GPU 加速的深度神经网络基元库</strong>，能够以高度优化的方式实现标准例程（如前向和反向卷积、池化层、归一化和激活层）。 全球的深度学习研究人员和框架开发者都依赖cuDNN 来实现高性能GPU 加速。</p>
<p>为了方便学习，我们就下载源码版本，而不下载安装版本：我这里选择的是：cudnn-linux-x86_64-8.9.0.131_cuda11-archive版本。如需其他版本，可<a target="_blank" rel="noopener" href="https://developer.nvidia.com/rdp/cudnn-download">自行下载</a></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">wget https://developer.nvidia.com/downloads/compute/cudnn/secure/8.9.0/local_installers/11.8/cudnn-linux-x86_64-8.9.0.131_cuda11-archive.tar.xz</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">解压</span></span><br><span class="line">tar -xf cudnn-linux-x86_64-8.9.0.131_cuda11-archive.tar.xz</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">重命名一下</span></span><br><span class="line">mv cudnn-linux-x86_64-8.9.0.131_cuda11-archive cudnn-8.9.0</span><br></pre></td></tr></table></figure>
<p>将cuDNN添加到动态链接库，<code>vim ~/.zshrc</code></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">export cuDNN_ROOT=/your cudnn path/</span><br><span class="line">export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$cuDNN_ROOT/lib</span><br></pre></td></tr></table></figure>
<p>更好的解决方案是，直接将cuDNN拷贝到CUDA的安装目录。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">在cuDNN目录下</span></span><br><span class="line">sudo cp cuda/include/* /usr/local/cuda-11.1/include</span><br><span class="line">sudo cp cuda/lib64/libcudnn* /usr/local/cuda-11.1/lib64</span><br><span class="line"></span><br><span class="line">sudo chmod +X /usr/local/cuda-11.1/include/cudnn*</span><br><span class="line">sudo chmod +X /usr/local/cuda-11.1/lib64/libcudnn*</span><br></pre></td></tr></table></figure>
<h3 id="5-3-测试环境"><a href="#5-3-测试环境" class="headerlink" title="5.3 测试环境"></a>5.3 测试环境</h3><p>在<code>TensorRT</code>目录下有个 <code>samples</code>文件夹，其中是官方测试用例。我随便挑一个，<code>sampleMNIST</code>试一下。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">TensorRT 目录下</span></span><br><span class="line">cd samples/sampleMNIST</span><br><span class="line">make</span><br></pre></td></tr></table></figure>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415145651872.png" alt=""></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">执行结果</span></span><br><span class="line">../../bin/sample_mnist</span><br></pre></td></tr></table></figure>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230415145751383.png" alt=""></p>
<p>大功告成！</p>
<h2 id="6、实际项目展示"><a href="#6、实际项目展示" class="headerlink" title="6、实际项目展示"></a>6、实际项目展示</h2></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://gitee.com/zwyywz/zwyywz.git">Zhouwy</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://gitee.com/zwyywz/zwyywz.git/2023/04/15/%E5%9C%A8ubuntu%E4%B8%8A%E4%BB%8E0%E5%BC%80%E5%A7%8B%E9%85%8D%E7%BD%AE%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/">https://gitee.com/zwyywz/zwyywz.git/2023/04/15/%E5%9C%A8ubuntu%E4%B8%8A%E4%BB%8E0%E5%BC%80%E5%A7%8B%E9%85%8D%E7%BD%AE%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://gitee.com/zwyywz/zwyywz.git" target="_blank">啊粥啊周舟の部落阁</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/zwyywz/tags/DeepLearning/">DeepLearning</a><a class="post-meta__tags" href="/zwyywz/tags/%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/">开发环境</a><a class="post-meta__tags" href="/zwyywz/tags/%E7%B3%BB%E7%BB%9F%E5%AE%89%E8%A3%85/">系统安装</a></div><div class="post_share"><div class="social-share" data-image="https://cdn.educba.com/academy/wp-content/uploads/2020/01/Deep-Learning.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/zwyywz/img/wechat.jpg" target="_blank"><img class="post-qr-code-img" src="/zwyywz/img/wechat.jpg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="/zwyywz/img/alipay.jpg" target="_blank"><img class="post-qr-code-img" src="/zwyywz/img/alipay.jpg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="next-post pull-full"><a href="/zwyywz/2023/01/15/zkViewYolo/" title="针对zkview平台上嵌入机器视觉算法的框架"><img class="cover" src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20230410111343844.png" onerror="onerror=null;src='/zwyywz/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">针对zkview平台上嵌入机器视觉算法的框架</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/zwyywz/2020/09/20/Mac%20M1%20Pro%20%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/" title="Mac M1 Pro 深度学习环境搭建"><img class="cover" src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/apple-macbook-pro-m1-2020-5-20230410110609763.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-09-20</div><div class="title">Mac M1 Pro 深度学习环境搭建</div></div></a></div><div><a href="/zwyywz/2022/05/22/TensorRT%E6%95%99%E7%A8%8B/" title="TensorRT实战教程"><img class="cover" src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/FI-1.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-05-22</div><div class="title">TensorRT实战教程</div></div></a></div><div><a href="/zwyywz/2021/06/15/%E5%9F%BA%E4%BA%8E%E6%9C%BA%E5%99%A8%E8%A7%86%E8%A7%89%E7%9A%84%E4%BB%BF%E7%94%9F%E6%9C%BA%E6%A2%B0%E6%89%8B%E6%8E%8C/" title="基于机器视觉的机械手掌"><img class="cover" src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/yolo.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-06-15</div><div class="title">基于机器视觉的机械手掌</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9C%A8Ubuntu%E4%B8%8A%E4%BB%8E0%E5%BC%80%E5%A7%8B%E9%85%8D%E7%BD%AE%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83"><span class="toc-number">1.</span> <span class="toc-text">在Ubuntu上从0开始配置深度学习开发环境</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1%E3%80%81%E5%AE%89%E8%A3%85ubuntu-server"><span class="toc-number">1.1.</span> <span class="toc-text">1、安装ubuntu server</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-Ventoy-%E5%90%AF%E5%8A%A8U%E7%9B%98"><span class="toc-number">1.1.1.</span> <span class="toc-text">1.1 Ventoy 启动U盘</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-%E5%AE%89%E8%A3%85ubuntu-server"><span class="toc-number">1.1.2.</span> <span class="toc-text">1.2 安装ubuntu server</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-3-%E8%BF%9C%E7%A8%8B%E8%BF%9E%E6%8E%A5"><span class="toc-number">1.1.3.</span> <span class="toc-text">1.3 远程连接</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2%E3%80%81%E9%85%8D%E7%BD%AE%E5%9F%BA%E7%A1%80%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83"><span class="toc-number">1.2.</span> <span class="toc-text">2、配置基础开发环境</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-%E6%9B%B4%E6%8D%A2%E5%9B%BD%E5%86%85%E6%BA%90%E4%BB%A5%E5%8F%8A%E9%85%8D%E7%BD%AE%E7%A7%91%E5%AD%A6%E4%B8%8A%E7%BD%91"><span class="toc-number">1.2.1.</span> <span class="toc-text">2.1 更换国内源以及配置科学上网</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-%E5%AE%89%E8%A3%85zsh%E5%92%8Coh-my-zsh-%EF%BC%8C%E6%8F%90%E5%8D%87%E7%BB%88%E7%AB%AF%E6%95%88%E7%8E%87"><span class="toc-number">1.2.2.</span> <span class="toc-text">2.2 安装zsh和oh-my-zsh ，提升终端效率</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3%E3%80%81%E5%AE%89%E8%A3%85%E6%98%BE%E5%8D%A1%E9%A9%B1%E5%8A%A8%E4%BB%A5%E5%8F%8ACUDA"><span class="toc-number">1.3.</span> <span class="toc-text">3、安装显卡驱动以及CUDA</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-1-%E5%AE%89%E8%A3%85%E6%98%BE%E5%8D%A1%E9%A9%B1%E5%8A%A8"><span class="toc-number">1.3.1.</span> <span class="toc-text">3.1. 安装显卡驱动</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-%E5%AE%89%E8%A3%85CUDA"><span class="toc-number">1.3.2.</span> <span class="toc-text">3.2 安装CUDA</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4%E3%80%81%E9%85%8D%E7%BD%AE%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83"><span class="toc-number">1.4.</span> <span class="toc-text">4、配置深度学习开发环境</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#4-1-%E5%AE%89%E8%A3%85conda%E7%94%A8%E4%BB%A5%E7%AE%A1%E7%90%86python%E7%89%88%E6%9C%AC"><span class="toc-number">1.4.1.</span> <span class="toc-text">4.1 安装conda用以管理python版本</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-2-PyTorch-%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83"><span class="toc-number">1.4.2.</span> <span class="toc-text">4.2 PyTorch 开发环境</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-2-TensorFlow-%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83"><span class="toc-number">1.4.3.</span> <span class="toc-text">4.2 TensorFlow 开发环境</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5%E3%80%81TRT%E6%A8%A1%E5%9E%8B%E9%83%A8%E7%BD%B2"><span class="toc-number">1.5.</span> <span class="toc-text">5、TRT模型部署</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#5-1-%E5%AE%89%E8%A3%85TensorRT"><span class="toc-number">1.5.1.</span> <span class="toc-text">5.1 安装TensorRT</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-2-%E5%AE%89%E8%A3%85cuDNN"><span class="toc-number">1.5.2.</span> <span class="toc-text">5.2 安装cuDNN</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-3-%E6%B5%8B%E8%AF%95%E7%8E%AF%E5%A2%83"><span class="toc-number">1.5.3.</span> <span class="toc-text">5.3 测试环境</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6%E3%80%81%E5%AE%9E%E9%99%85%E9%A1%B9%E7%9B%AE%E5%B1%95%E7%A4%BA"><span class="toc-number">1.6.</span> <span class="toc-text">6、实际项目展示</span></a></li></ol></li></ol></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By Zhouwy</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/zwyywz/js/utils.js"></script><script src="/zwyywz/js/main.js"></script><script src="/zwyywz/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>